package game.objects
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.net.NetGroupSendMode;
	import flash.utils.Timer;
	import game.events.GameEvent;
	/**
	 * ...
	 * @author yatinglo
	 */
	public class TimeBoard extends MovieClip 
	{
		private var i:int = 0;
		
		private var gameTimer:Timer;
		private var gameTime:uint;
		private var gameTimerInerval:uint;
		private var gameTimerRepeat:uint;
		private var maingame:main;
		private var locationX:Number = 953.3;
		private var locationY:Number = 48.35;
		
		public function TimeBoard(maingame:main) {
			//stop();
			this.maingame = maingame;
			this.gameTime = maingame.gameValue.getGameTime();
			this.gotoAndStop(gameTime); 	
			gameTimerInerval = 1000;
			gameTimerRepeat = gameTime;
			this.x = locationX;
			this.y = locationY;
			
			this.gameTimerSetup();
			maingame.stage.addChild(this);
		}
		
		public function gameTimerSetup():void {
			gameTimer = new Timer(gameTimerInerval, gameTimerRepeat);
			gameTimer.addEventListener(TimerEvent.TIMER, this.timerEventHandle);
			gameTimer.addEventListener(TimerEvent.TIMER_COMPLETE, this.timerCompleteHandle);
			gameTimer.start();
		}
		
		public function timerEventHandle(e:TimerEvent):void {
			trace(gameTimer.currentCount.toString());		
			this.gotoAndStop(gameTime - i++);
			/*if (i > gameTime)
			{
				maingame.stage.dispatchEvent(new Event(GameEvent.GAME_OVER, false, false));
			}*/
			return;
		}
		
		public function timerCompleteHandle(e:TimerEvent):void {
			trace("game timer complete");
			maingame.stage.dispatchEvent(new Event(GameEvent.GAME_OVER, false, false));
		}
		
		public function remove():void {
			parent.removeChild(this);
			gameTimer.removeEventListener(TimerEvent.TIMER, this.timerEventHandle);
			gameTimer.removeEventListener(TimerEvent.TIMER_COMPLETE, this.timerCompleteHandle);
		}
		
	}
	
}